﻿public class Person:IComparable
{
    public string Name { get; set; }
    public int Age { get; set; }
    public bool Sex { get; set; }

    public Person(string name,bool sex,int age)
    {
        this.Name = name;
        this.Age = age;
        this.Sex = sex;
    }
    public int CompareTo(object obj2)
    {
        if (!(obj2 is Person))
            throw new ArgumentException();
        Person rec2 = (Person)obj2;
        return this.Name.CompareTo(rec2.Name);
    }
    public override string ToString()
    {
        return Name;
    }
}

public class AgeComparer : IComparable<Person>
{
    public int Compare(Person p1, Person p2)
    {
        return p1.Age- p2.Age;
    }
}

//public static void Main(string[] args)
{
       List<Person> persons = new List<Person>();
    Console.WriteLine("original array:");
    persons.ForEach(p=>Console.WriteLine(p.Name));

    Console.WriteLine("sort(Icompable):");
    persons.Sort();
    persons.ForEach(p => Console.WriteLine(p);
}